package com.shiguo365.market.display.util;

import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;

import com.maimengmami.waveswiperefreshlayout.WaveSwipeRefreshLayout;
import com.shiguo365.market.R;
import com.shiguo365.market.display.fragment.SearchFragment;
import com.shiguo365.market.utils.HandlerUtils;
import com.yalantis.phoenix.PullToRefreshView;


public final class RefreshUtils {

    private RefreshUtils() {}

    public static void initOnCreate(@NonNull SwipeRefreshLayout refreshLayout, @NonNull SwipeRefreshLayout.OnRefreshListener refreshListener) {
        refreshLayout.setColorSchemeResources(R.color.red_light, R.color.green_light, R.color.blue_light, R.color.orange_light);
        refreshLayout.setOnRefreshListener(refreshListener);
    }

    /**
     * TODO refreshLayout无法直接在onCreate中设置刷新状态
     */
    public static void refreshOnCreate(@NonNull final SwipeRefreshLayout refreshLayout, @NonNull final SwipeRefreshLayout.OnRefreshListener refreshListener) {
        HandlerUtils.postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setRefreshing(true);
                refreshListener.onRefresh();
            }

        }, 100);
    }

    public static void initOnCreate(@NonNull WaveSwipeRefreshLayout refreshLayout, @NonNull WaveSwipeRefreshLayout.OnRefreshListener refreshListener) {
        refreshLayout.setColorSchemeResources(R.color.red_light, R.color.green_light, R.color.blue_light, R.color.orange_light);
        refreshLayout.setOnRefreshListener(refreshListener);
    }

    /**
     * TODO refreshLayout无法直接在onCreate中设置刷新状态
     */
    public static void refreshOnCreate(@NonNull final WaveSwipeRefreshLayout refreshLayout, @NonNull final WaveSwipeRefreshLayout.OnRefreshListener refreshListener) {
        HandlerUtils.postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setRefreshing(true);
                refreshListener.onRefresh();
            }

        }, 100);
    }


    public static void initOnCreate(@NonNull PullToRefreshView refreshLayout, @NonNull PullToRefreshView.OnRefreshListener refreshListener) {
        refreshLayout.setOnRefreshListener(refreshListener);
    }

    /**
     * TODO refreshLayout无法直接在onCreate中设置刷新状态
     */
    public static void refreshOnCreate(@NonNull final PullToRefreshView refreshLayout, @NonNull final PullToRefreshView.OnRefreshListener refreshListener) {
        HandlerUtils.postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setRefreshing(true);
                refreshListener.onRefresh();
            }

        }, 100);
    }

}
